package vip.web3.admin.sys.mapper;

import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.factory.Mappers;
import org.springframework.util.CollectionUtils;
import vip.web3.admin.sys.entity.biz.ARecordEntity;
import vip.web3.admin.sys.vo.biz.BizRecordVo;
import vip.web3.admin.sys.vo.biz.export.*;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

@Mapper
public interface ARecordMapper {

    ARecordMapper INSTANCE = Mappers.getMapper(ARecordMapper.class);

    @Mapping(target = "amount", ignore = true)
    @Mapping(target = "fee", ignore = true)
    BizRecordVo toBizRecordVo(ARecordEntity entity);

    default BizRecordVo toAdminBizRecordVo(ARecordEntity entity) {
        BizRecordVo recordVo = toBizRecordVo(entity);
        if (Objects.nonNull(recordVo) && Objects.nonNull(entity)) {
            BigDecimal amount = Objects.isNull(entity.getAmount()) ? BigDecimal.ZERO : entity.getAmount();
            BigDecimal fee = Objects.isNull(entity.getFee()) ? BigDecimal.ZERO : entity.getFee();

            recordVo.setAmount(amount.stripTrailingZeros().toPlainString());
            recordVo.setFee(fee.stripTrailingZeros().toPlainString());
        }
        return recordVo;
    }

    default List<BizRecordVo> toAdminBizRecordVoList(List<ARecordEntity> entity) {
        if (CollectionUtils.isEmpty(entity)) {
            return null;
        }

        List<BizRecordVo> list = new ArrayList<>(entity.size());
        for (ARecordEntity recordEntity : entity) {
            list.add(this.toAdminBizRecordVo(recordEntity));
        }

        return list;
    }

    List<ExRecordVo> toExRecordVos(List<BizRecordVo> recordVos);

    List<ExUsdtVo> toExUsdtVos(List<BizRecordVo> recordVos);

    List<ExCnyVo> toExCnyVos(List<BizRecordVo> recordVos);

    List<ExReUsdtVo> toEExReUsdtVos(List<BizRecordVo> recordVos);

    List<ExReCnyVo> toExReCnyVos(List<BizRecordVo> recordVos);
}
